<?php 
    include_once('./public/header.php');
    if(isset($_GET['keywords']) && !empty($_GET['keywords'])){
        $where ='where title like "%'.$_GET['keywords'].'%"';
        $keywords = $_GET['keywords'];
    }else{
        $where = '';
        $keywords = '';
    }
    $page = dispage($config,'article','as a left join user as u on a.uid=u.id '.$where
            ,'a.title,a.ctime,a.pic,a.clicknum,a.content,a.status,u.nicname as uid,a.id as id');
    $res = $page[4];
?>
<ul>
    <li class="active"><a href="index.php"><span>Home Page</span></a></li>
    <li><a href=""><span>Register</span></a></li>
    <li><a href=""><span>LogIn</span></a></li>
    <li><a href=""><span>Update Pwd</span></a></li>
    <li><a href=""><span>LogOff</span></a></li>
<?php
    if(!empty($_SESSION)){
        echo '<li><a href=""><span>welcome: '.$_SESSION['uname'].'</span></a></li>';
    }
?>
</ul>
<?php include_once('./public/middle.php');?>
  <div class="copyrights">Collect from <a href="http://www.cssmoban.com/" title="网站模板">网站模板</a></div>
  <div class="content">
    <div class="content_resize">
      <div class="mainbar">
      <?php
        foreach ($res as $k => $v) {
            if($v['status'] == '已审核'){
                echo '<div class="article">';
                echo '<h2>'.$v['title'].'</h2>';
                echo '<p class="infopost"> Posted on <span class="date">'.date('Y-m-d H:i:s',$v['ctime']).'</span> by <a href="#">'.$v['uid'].'</a> &nbsp;&nbsp;|&nbsp;&nbsp; 点击量：'.$v['clicknum'].'</p>';
                echo '<div class="clr"></div>';
                echo '<div class="img"><img src="/public/upload/'.$v['pic'].'" width="162" height="192" alt="" class="fl" /></div>';
                echo '<div class="post_content">';
                echo '<p>'.mb_substr($v['content'],0,500,'utf-8').'</p>';
                echo '<p class="spec"><a href="blog.php?id='.$v['id'].'" class="rm">Read more</a></p>';
                echo '</div>';
                echo '<div class="clr"></div>';
                echo '</div>';
            }
        }
      ?>
        <div class="article">
          <br>
            <a href="<?php echo $_SERVER['PHP_SELF'] ?>?keywords=<?php echo $keywords?>&p=1">首页</a>
            <a href="<?php echo $_SERVER['PHP_SELF'] ?>?keywords=<?php echo $keywords?>&p=<?php echo $page[0]?>">上一页</a>
            <?php
                $leftRight = 1;
                $left = $page[3] - $leftRight;
                $right = $page[3] + $leftRight;
                if($left < 1){
                    $left = 1;
                    $right = $left + 2*$leftRight;
                }
                if($right > $page[2]){
                    $right = $page[2];
                    if($right > 2*$leftRight){
                        $left = $right - 2*$leftRight;
                    }else{
                        $left = 1;
                    }
                }

                if($left > 1){
                    echo '...';
                }

                for($i = $left;$i <= $right;$i++){
                    $color = ($i == $page[3])?'style = "color:red;font-weight:900"':'';
                    echo '<a '.$color.' href="'.$_SERVER['PHP_SELF'].'?keywords='.$keywords.'&p='.$i.'">'.$i.'
                    </a>&nbsp;';
                }

                if($right < $page[2]){
                    echo '...';
                }
            ?>
            <a href="<?php echo $_SERVER['PHP_SELF'] ?>?keywords=<?php echo $keywords?>&p=<?php echo $page[1]?>">下一页</a>
            <a href="<?php echo $_SERVER['PHP_SELF'] ?>?keywords=<?php echo $keywords?>&p=<?php echo $page[2]?>">尾页</a>
            <span>总共<?php echo $page[2]?>页，当前：<?php echo $page[3]?>/<?php echo $page[2]?></span>
            <hr>
            <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="get">
                <input type="hidden" name="keywords" value="<?php echo $keywords?>">
                跳转至：<input type="text" name="p">
                <input type="submit" value="go">
            </form>
        </div>
      </div>
<?php include_once('./public/footer.php');?>